package initialize

import (
	"github.com/fsnotify/fsnotify"
	"github.com/spf13/viper"
	"go.uber.org/zap"
	"user_bff/global"
)

func InitConfig() {
	viper.SetConfigFile("../user_bff/config/dev_config.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		zap.S().Panic(err)
	}
	err = viper.Unmarshal(&global.ServerConfig)
	if err != nil {
		zap.S().Panic(err)
	}
	go func() {
		viper.OnConfigChange(func(in fsnotify.Event) {
			err = viper.Unmarshal(&global.ServerConfig)
			if err != nil {
				zap.S().Panic(err)
			}
		})
		viper.WatchConfig()
	}()
}
